var tmp = " hello world \t"; var res1 = tmp.Trim(); // "hello world" var res2 = tmp.Replace(" ", String.Empty); // "helloworld\t"